//
//  LimitTabBarViewController.m
//  LimitFree
//
//  Created by LZXuan on 15-6-25.
//  Copyright (c) 2015年 轩哥. All rights reserved.
//

#import "LimitTabBarViewController.h"
#import "AppListViewController.h"

@interface LimitTabBarViewController ()

@end

@implementation LimitTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatViewControllers];
}
#pragma mark - 创建子视图控制器
- (void)creatViewControllers {
    
    NSArray *urlArr = @[kLimitUrl,kReduceUrl,kFreeUrl,kSubjectUrl,kHotUrl];
    NSArray *categoryArr = @[kLimitType,kReduceType,kFreeType,kSubjectType,kHotType];
    
    //解析plist
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Controllers" ofType:@"plist"];
    NSArray *fileArr = [NSArray arrayWithContentsOfFile:path];
    
    NSMutableArray *vcArr = [[NSMutableArray alloc] init];
    int i = 0;
    //遍历数组
    for (NSDictionary *dict in fileArr) {
        NSString *title = dict[@"title"];
        NSString *iconName = dict[@"iconName"];
        NSString *className = dict[@"className"];
        //把一个类名字符串 转化为Class 类型
        Class cls = NSClassFromString(className);
        //cls 是一个变量  可以执行类的加方法
        AppListViewController *appVC = [[cls alloc] init];
        
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:appVC];
        appVC.title = title;
        //传值 把url 传入
        appVC.requestUrl = urlArr[i];
        appVC.categoryType = categoryArr[i];
        i++;
        
        /*
         //上面一句等价于下面两句
        appVC.navigationItem.title = title;
        nav.tabBarItem.title = title;
         */
        
        nav.tabBarItem.image = [UIImage imageNamed:iconName];
        //加入数组
        [vcArr addObject:nav];
    }
    self.viewControllers = vcArr;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
